/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cc.altius.web.controller;

import cc.altius.model.CallType;
import cc.altius.model.Disposition;
import cc.altius.model.Doctor;
import cc.altius.model.HealthSpringCenter;
import cc.altius.model.Illness;
import cc.altius.model.OfficeLocation;
import cc.altius.model.PaymentType;
import cc.altius.model.Relation;
import cc.altius.service.CenterService;
import cc.altius.service.CustomerService;
import cc.altius.service.DoctorService;
import cc.altius.service.HospitalService;
import cc.altius.service.OfficeLocationService;
import cc.altius.service.SpecialistService;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jasypt.util.numeric.BasicIntegerNumberEncryptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * @author mudassar
 */
@Controller
public class TicketController {

    @Autowired
    private CustomerService customerService;
    @Autowired
    private CenterService centerService;
    @Autowired
    private OfficeLocationService officeLocationService;
    @Autowired
    private DoctorService doctorService;
    @Autowired
    private HospitalService hospitalService;
    @Autowired
    private SpecialistService specialistService;
    @Autowired
    private BasicIntegerNumberEncryptor basicIntegerNumberEncryptor;

    @ModelAttribute("illnessList")
    public List<Illness> populateIllnessList() {
        return customerService.getIllnessList();
    }

    @ModelAttribute("centerList")
    public List<HealthSpringCenter> populateCenterList() {
        return centerService.getCenterList();
    }

    @ModelAttribute("paymentTypeList")
    List<PaymentType> getPaymentTypeList() {
        return this.customerService.getPaymentTypeList();
    }

    @ModelAttribute("relationList")
    List<Relation> getRelationList() {
        return this.customerService.getRelationList();
    }

    @ModelAttribute("callTypeList")
    List<CallType> getCallTypeList() {
        return this.customerService.getCallTypeList();
    }

    @ModelAttribute("dispositionList")
    List<Disposition> getDispositionList() {
        List<Disposition> list = this.customerService.getDispositionList();
        System.out.println("list" + list.get(0).getDispositionId());
        return list;
    }

    @ModelAttribute("officeList")
    public List<OfficeLocation> getOfficeLocationsList() {
        return this.officeLocationService.getOfficeLocationsList();
    }

    @ModelAttribute("doctorList")
    public List<Doctor> populateDoctorList() {
        return doctorService.getDoctorList();
    }
    
    @RequestMapping(value = "ajaxCallForDispositionListForTicket.htm", method = RequestMethod.GET)
    public @ResponseBody
    String doAjaxDispositionPopulate(@RequestParam(value = "callTypeId1") int callTypeId) {
        String json;
        List<Disposition> dispositionList = this.customerService.getDispositionList(callTypeId);
        Gson gson = new Gson();
        List list = new ArrayList();
        for (Disposition d : dispositionList) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", d.getDispositionId());
            map.put("label", d.getDispositionName());
            map.put("value", d.getDispositionId());
            list.add(map);
        }
        Type typeList = new TypeToken<List>() {
        }.getType();
        json = gson.toJson(list, typeList);
        System.out.println("json :" + json);
        return json;
    }


    
}
